package com.hdd.art.biz.show.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hdd.art.biz.painting.entity.PaintingWorks;
import com.hdd.art.biz.show.entity.ShowroomScreen;
import com.hdd.art.biz.show.mapper.ShowroomScreenMapper;
import com.hdd.art.biz.show.service.ShowroomScreenService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.micrometer.core.instrument.util.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-07-05
 */
@Service
public class ShowroomScreenServiceImpl  extends ServiceImpl<ShowroomScreenMapper, ShowroomScreen> implements ShowroomScreenService {

    @Override
    public List<ShowroomScreen> list(String artId,Integer roomId, Integer pageNo, Integer pageSize) {
        QueryWrapper<ShowroomScreen> wrapper = new QueryWrapper();
        Page<ShowroomScreen> pages = new Page<>(pageNo,pageSize);
        wrapper.eq("art_id",artId);
        wrapper.eq("room_id",roomId);
        wrapper.orderByDesc("create_time");
        IPage<ShowroomScreen> mapIPage = baseMapper.selectPage(pages, wrapper);
        return mapIPage.getRecords();
    }

    @Override
    public void addShowRoomScreen(ShowroomScreen screen) {

        baseMapper.insert(screen);
    }

    @Override
    public void updateShowRoomScreen(ShowroomScreen screen) {

        baseMapper.updateById(screen);
    }

    @Override
    public void delShowRoomScreen(Integer id) {

        baseMapper.deleteById(id);
    }

    @Override
    public ShowroomScreen findShowRoomScreen(Integer id) {
        return baseMapper.selectById(id);
    }


    @Override
    public void setDef(Integer roomID,Integer id){
        ShowroomScreen screen = new ShowroomScreen();
        screen.setDef("F");
        QueryWrapper<ShowroomScreen> wrapper = new QueryWrapper();
        wrapper.eq("room_id",roomID);
        baseMapper.update(screen,wrapper);
        wrapper = new QueryWrapper();
        wrapper.eq("id",id);
        screen.setDef("T");
        baseMapper.update(screen,wrapper);
    }


}
